<?php
/**
 * An exception class extendion specially for the PHPrail.
 *
 * PHP versions 5
 *
 * Copyright (C)
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
 * Fundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * @author Bastian Schröder <bs@chemanet.de>
 * @version 2007-12-08
 * @package rail
 */
class rail_exception extends Exception {

	/**
	 * The debug level. Possible values are: 0 = no logging, 1 = log all messages
	 *
	 * @var int
	 */
	protected $debug_level = 0;

	/**
	 * An message for this exception.
	 *
	 * @var string
	 */
	protected $message;

	/**
	 * The rail_object who has throwed this exception.
	 *
	 * @var rail_object
	 */
	protected $rail_object;


	/**
	 * Constructor
	 *
	 * @param rail_object $pRailObject
	 * @param string $pMessage
	 */
	public function __construct( $pRailObject = null, $pMessage = 'Unknown exception' ){
		$this->rail_object = $pRailObject;
		$this->message = ( $pRailObject != null ? 'rail_object#' . $pRailObject->get_id() . ': ' : '' ) . $pMessage;

		// log message
		if( $this->debug_level >= 1 )
			error_log( $this->message, 0 );

		parent::__construct( $this->message, 0 );
	}

} // End of rail_exception
?>